<?php
/**
 * 《统计分析》实现类
 *
 * @author 孙晓晔
 * @version $Id: Mold.class.php 1053 2010-04-07 11:15:15Z sunxy $
 */
require_once(dirname(__FILE__) . '/Purchase.class.php');

class PurchaseCk extends Purchase {

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}
	
	/**
	 * 
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function tab($controller, $request) {		
		$data = array(
			'物料需求' => array('cc'=>'material.php?do=Bom.group', 'js'=>''),
			'采购信息' => array('cc'=>'material.php?do=Purchase.group', 'js'=>''),
			'采购明细' => array('cc'=>'material.php?do=RecordIn.group', 'js'=>''),
			'入库明细' => array('cc'=>'material.php?do=In.group', 'js'=>''),
		);
		
		$ret = $this->_tab($data);

		$controller->assign_by_ref('result', $ret);

		$controller->display($request, 'tab');
		return true;
	}
	
	function find($controller, $request) {
		$this->pretreat($controller);
	
		$controller->assign('t1', strtotime('-3 month'));
	
		$emp = array(
			// '-' => '请选择',
			'emp' => '采购员',
			'oper' => '录入员',
		);
	
		$controller->assign_by_ref('emp_option', $emp);
	
		$controller->display($request, 'material/in/purchase/ck/find');
		return true;
	}
	
	function findPost($controller, $request) {
		$this->pretreat($controller);
	
		$this->findPara($controller, $request);
	
		$mold_s = $this->_input($request['mold_s']);
	
		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s a %s %s";
		$where = $this->_where($request);
		$orderby = $this->_orderby();
	
		if (empty($mold_s)) {
			$fmt = "SELECT * FROM %s a %s %s";
			$sql = sprintf($fmt, $this->tbl, $where, $orderby);
		} else {
			$fmt = "SELECT a.* FROM %s a, %s b %s GROUP BY id %s ";
			$sql = sprintf($fmt, $this->tbl, Constant::tbl_wl_record_in, $where, $orderby);
		}
	
		debug($sql);
	
		// $sql = sprintf($fmt, $this->tbl, $where, $orderby);
		// debug($sql);
	
		$pager_option = array (
				'db' => $db,
				'sql' => $sql,
				'PageSize' => $this->pagesize,
				'CurrentPageID' => $request['p'],
				'numItems' => $request['n']
		);
	
		$pager = @new Pager($pager_option);
		$data = $pager->getPageData();
	
		if ($pager->number > 0) {
	
			$count = 0;
			$from = $pager->from;
			while ($count < $pager->number) {
				$row = $data[$count];
				$row = $this->_view(null, $row);
	
				$row['num_'] = $this->_num('purchase', $row['id']);
				// $row['color'] = $this->_status_color($row);
	
				$row = $this->_orderby_x($controller, $row, $this->orderby_s);
	
				$data[$count] = $row;
				$count++;
			}
			$controller->assign_by_ref('result', $data);
			$controller->assign_by_ref('pager', $pager);
		}
	
		$controller->display($request, 'material/in/purchase/ck/list');
		return true;
	}
	
	function view($controller, $request) {
		$this->pretreat($controller);
	
		$id = $request['id'];
		$row = $this->_view($id);
	
		$controller->assign_by_ref('result', $row);
	
		$record_in = $this->record_in($id);
		$controller->assign_by_ref('record_in', $record_in);
	
		$len = count($record_in);
		if ($len > 11) {
			$blank = array();
		} else {
			$blank = range(1, 12 - $len , 1);
			$controller->assign_by_ref('blank', $blank);
		}
	
		if ($request['view'] == '2') {
			$controller->display($request, 'material/in/purchase/view_2');
		} else {
			$controller->display($request, 'material/in/purchase/ck/view');
		}
	
		return true;
	}
}
?>